/*
 * Copyright 2023 The Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *@file    : camera_param.h
 *@brief   : camera param, image size
 *@authors : zhanglei
 *@version : v1.0
 *@data    : 2023/6/13
 *
 */

#ifndef UNDISTORTION_H_
#define UNDISTORTION_H_	

#include <Eigen/Dense>
#include <opencv2/opencv.hpp>

#define FRAME_WIDTH 640
#define FRAME_HEIGH 480

class Undistortion {
public:
	Undistortion(const std::string& path);
	void ImageResize(cv::Mat& image, const cv::Mat& frame);
	void UnDistortionKeyPoint(cv::KeyPoint& un_kp, cv::KeyPoint& resize_kp,const cv::KeyPoint& kp);
	void UnDistortionKeyPoint(cv::KeyPoint& un_kp, const cv::KeyPoint& kp);
	Eigen::Vector3d NormalizedPoint(const cv::KeyPoint& undistorted_kp);
	void DistortionKeyPoint(cv::KeyPoint& kp,const cv::KeyPoint& un_kp);

	bool IsInMask(const cv::KeyPoint& kp);
	
	Eigen::Matrix3d read_intrinsic();

	cv::Size image_size;
    cv::Mat K;  // 内参矩阵
    cv::Mat D;  // 畸变系数
    cv::Mat R;  // 矫正矩阵
    cv::Mat P;  // 投影矩阵

    double image_width_scale_ratio_; // x

    double image_height_scale_ratio_; // y

};

#endif